package com.cooper.mediadb.online;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.cooper.scraper.DownloadException;
import com.cooper.scraper.HttpDownload;
import com.cooper.scraper.ScraperException;

public class AnalyzeMovieweb extends AnalyzeVideo {

	public AnalyzeMovieweb(HttpDownload httpDownload, String url, String format) {
		super(httpDownload, url, format);
	}

	@Override
	public List<String> analyzeVideo() throws DownloadException,
			ScraperException, IOException {
		List<String> result = new ArrayList<String>();

		String page = httpDownload.downloadPage(url + "/play");
		Matcher m = Pattern
				.compile(
						"\\{\"videoId\":\"([^\"]*)\",\"idx\":\\d*,\"i\":\\d*,\"ii\":(\\d*),\"iii\":\"([^\"]*)\",\"iiii\":\"([^\"]*)\",")
				.matcher(page);
		if (m.find()) {
			result.add("http://wpc.556e.edgecastcdn.net/80556E/video/"
					+ m.group(1) + "_" + m.group(2) + m.group(3) + "?"
					+ m.group(4));
		}
		return result;
	}

}
